﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Text;

namespace Windstamp.Utility.BookDownload.Common {
    /// <summary>
    /// Url 请求助手类
    /// </summary>
    public class UrlRequestHelper {
        /// <summary>
        /// 创建 Url 请求
        /// </summary>
        /// <param name="url">请求的 Url</param>
        /// <param name="encoding">请求页面的编码格式</param>
        /// <returns></returns>
        public static HttpWebRequest BuildRequest(string url, string encoding) {
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
            request.Method = "GET";
            request.ContentType = "text/html;charset=" + encoding;
            request.UserAgent = "Mozilla/5.0 (Windows NT 6.2; WOW64; rv:26.0) Gecko/20100101 Firefox/26.0";
            request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
            //request.Headers.Add("Accept-Encoding", "gzip, deflate");
            request.Headers.Add("Accept-Language", "zh-cn,zh;q=0.8,en-us;q=0.5,en;q=0.3");
            return request;
        }
    }
}
